package com.cp.order.platform.web;

import java.util.HashMap;
import java.util.Map;

import com.cp.order.model.GoodsBrand;
import com.cp.order.platform.BaseController;

public class GoodsBrandController extends BaseController {

	public void index() {
		renderFreeMarker("brand.html");
	}

	public void addBrand() {
		renderFreeMarker("brandAdd.html");
	}

	public void editBrand() {
		renderFreeMarker("brandEdit.html");
	}

	public void list() {
		int cpage = getParaToInt("cpage", 1);
		int pageSize = getParaToInt("pagesize", 10);
		HashMap<String, String> params = new HashMap<>();
		returnOK(GoodsBrand.dao.queryList(params, cpage, pageSize));
	}

	public void add() {
		GoodsBrand goodsBrand = getModel(GoodsBrand.class, "brand");
		goodsBrand.setStatus(0);
		if (goodsBrand.save()) {
			returnOK();
		} else {
			returnBusinessError("添加失败");
		}
	}

	public void update() {
		GoodsBrand goodsBrand = getModel(GoodsBrand.class, "brand");
		if (goodsBrand.update()) {
			returnOK();
		} else {
			returnBusinessError("修改失败");
		}
	}

	public void delete() {
		int id = getParaToInt("id");
		GoodsBrand goodsBrand = new GoodsBrand();
		goodsBrand.setId(id);
		goodsBrand.setStatus(1);// 逻辑删除
		if (goodsBrand.update()) {
			returnOK();
		} else {
			returnBusinessError("删除失败");
		}
	}

	public void judge() {
		GoodsBrand goodsBrand = GoodsBrand.dao.judgeName(getPara("brandName"));
		Map<String, Object> map = new HashMap<String, Object>();
		if (goodsBrand == null) {
			map.put("isHas", false);
		} else {
			map.put("isHas", true);
		}
		returnOK(map);
	}

}
